
(function () {
  var buttonAudited = {
    title:"审核",
    action: function () {
      var _viewGrid = this.view.viewGrid;
      var selectedRecord = _viewGrid.getSelectedRecord();
      var row = _viewGrid.getRecordIndex(selectedRecord);
      if(selectedRecord){
    	  var data = {};
    	  data.id=selectedRecord[OB.Constants.ID];
    	  data.tag=1;//审核
    	  isc.confirm("确定审核通过？",function(ok){
    		  if(ok){
	    		  var callback=function(response, data, request){
						if(data.result){
							_viewGrid.setEditValue(row,'audited',true);
						}else{
							isc.showMessage(data.msg,isc.OBMessageBar.TYPE_ERROR);
						}
					};
	    		  OB.RemoteCallManager.call("com.mes.handler.EmesProcessRouteHandler",data,{},callback);
    		  }
    	  });
      }
    },
    buttonType: 'buttonAudited',
    updateState: function () {
      var view = this.view,
          form = view.viewForm,
          grid = view.viewGrid,
          selectedRecords = grid.getSelectedRecords();
      //isShowingForm  打开表格页面    如 新建 双击编辑 true
      //isNew  新建表格 true 
      //isEditingGrid 在某一个点击对应行的编辑按钮时候 true
      if (view.isShowingForm || view.isEditingGrid) {
          this.setDisabled(true);
      } else {
    	  var selectedRecord = grid.getSelectedRecord();
          if(selectedRecord && selectedRecords.length==1){
        	  this.setDisabled(false);
          }else {
            this.setDisabled(true);
          }
      }
    }
  };

  // register the button for the sales order tab
  OB.ToolbarRegistry.registerButton(buttonAudited.buttonType, isc.OBToolbarIconButton, buttonAudited, 100, 'A15E082EE2874D9598A6D8FB2DDE6EF8');
  
////***********************************************************************************///////////////////////////   
  
  var buttonDefault = {
	    title:"默认",
	    action: function () {
	      var _viewGrid = this.view.viewGrid;
	      var selectedRecord = _viewGrid.getSelectedRecord();
	      var row = _viewGrid.getRecordIndex(selectedRecord);
	      if(selectedRecord){
	    	  var data = {};
	    	  data.id=selectedRecord[OB.Constants.ID];
	    	  
	    	  data.tag=2;//默认
	    	  isc.confirm("设置默认？",function(ok){
	    		  if(ok){
		    		  var callback=function(response, data, request){
		    			    if(data.result){
		    			    	_viewGrid.setEditValue(row,'default',true);
							}else{
								isc.showMessage(data.msg,isc.OBMessageBar.TYPE_ERROR);
							}
						};
		    		  OB.RemoteCallManager.call("com.mes.handler.EmesProcessRouteHandler",data,{},callback);
	    		  }
	    	  });
	      }
	    },
	    buttonType: 'buttonDefault',
	    updateState: function () {
	      var view = this.view,
	          form = view.viewForm,
	          grid = view.viewGrid,
	          selectedRecords = grid.getSelectedRecords();
	      //isShowingForm  打开表格页面    如 新建 双击编辑 true
	      //isNew  新建表格 true 
	      //isEditingGrid 在某一个点击对应行的编辑按钮时候 true
	      if (view.isShowingForm || view.isEditingGrid) {
	          this.setDisabled(true);
	      } else {
	    	  var selectedRecord = grid.getSelectedRecord();
	          if(selectedRecord && selectedRecords.length==1){
	        	  this.setDisabled(false);
	          }else {
	            this.setDisabled(true);
	          }
	      }
	    }
	  };

	  // register the button for the sales order tab
	  OB.ToolbarRegistry.registerButton(buttonDefault.buttonType, isc.OBToolbarIconButton, buttonDefault, 101, 'A15E082EE2874D9598A6D8FB2DDE6EF8');
  
}());

